﻿using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.DrugTrade.Web.Enterprise.DrugLibQuery
{
    public partial class LimitPricesPublicity : System.Web.UI.Page
    {
        IBLL_Goods ig = Factory.BLL_Goods();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (DateTime.Now < Convert.ToDateTime("2015-12-21 17:00:00"))
                {
                    HZ.Web.WebUtil.Alert("公示日期：2015年12月14日至12月21日 17:00:00");
                    Bind();
                }
                else
                {
                    HZ.Web.MessageBox.AlertAndRedirect("公示已结束", "~/Enterprise/defaultContent.aspx");
                }
            }
        }

        public string GetWhere()
        {
            string where = string.Empty;
            if (!string.IsNullOrEmpty(txtGoodsId.Text.Trim()))
            {
                where += " and a.goodsid like '%" + txtGoodsId.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtGoodsName.Text.Trim()))
            {
                where += " and goodsname like '%" + txtGoodsName.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtOutLook.Text.Trim()))
            {
                where += " and outlookc like '%" + txtOutLook.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtMaterial.Text.Trim()))
            {
                where += " and Material like '%" + txtMaterial.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.Trim()))
            {
                where += " and unit like '%" + txtUnit.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtPackUnit.Text.Trim()))
            {
                where += " and packunit like '%" + txtPackUnit.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtQualityLevel.Text.Trim()))
            {
                where += " and QualityLevel like '%" + txtQualityLevel.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtProduceCompany_SC.Text.Trim()))
            {
                where += " and CompanyName_SC_tb like '%" + txtProduceCompany_SC.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txtpinyincode.Text.Trim()))
            {
                where += " and pinyincode like '%" + txtpinyincode.Text.Trim() + "%'";
            }
            return where;
        }

        public void Bind()
        {
            int totalCount = 0;
            gvwGoodsList.DataSource = ig.GetLimitPriceByWhere(GetWhere(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwGoodsList.DataBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                //清空数据
                txtGoodsId.Text = "";
                //txtFactor.Text = "";
                txtQualityLevel.Text = "";
                txtPackUnit.Text = "";
                //txtPack.Text = "";
                txtProduceCompany_SC.Text = "";
                txtGoodsName.Text = "";
                txtUnit.Text = "";
            }
        }
    }
}